<?php

namespace PackageSpy;

class CzechPostPackageInfoProvider extends PackageInfoProvider0 implements PackageInfoProviderItf{
	
	/**
	 * State of provider
	 */
	public function getProviderState(){
		
	}
	
	/**
	 * (non-PHPdoc)
	 * @see \PackageSpy\PackageInfoProviderItf::searchResult()
	 */
	public function searchResult($packageId){
		
		$pageContent = $this->loadResultPage($packageId);
		
		//TODO cp parsing response into result object
		//$result = "";
		$providerResult = new ProviderInfoResult();
		$item = $pageContent->getElementById("content");
		$itemstable = $item->getElementsByTagName("table");
		$itemstr = $itemstable->item(0)->getElementsByTagName("tr");
		for ($i = 0; $i < $itemstr->length; $i++){
			//$result.=$itemstr->item($i)->nodeValue."<br/>";
			$providerResult->addStateOfPackage($itemstr->item($i)->nodeValue);
		}
		
		
		return $providerResult;
	}
	
	protected function getUrl($packageId){
		return "http://www.ceskaposta.cz/cz/nastroje/sledovani-zasilky.php?locale=CZ&send.x=43&send.y=7&go=ok&barcode=".$packageId;
	}
}
